home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS04.ADF / C / ownlib.c < prev    next >
C/C++ Source or Header  |  1985-10-30  |  5KB  |  205 lines

  1. /****************************************************************
  2. *                                                               *
  3. * Copyright 1985, Commodore Amiga Inc.  All rights reserved.    *
  4. * No part of this program may be reproduced, transmitted,       *
  5. * transcribed, stored in retrieval system, or translated into   *
  6. * any language or computer language, in any form or by any      *
  7. * means, electronic, mechanical, magnetic, optical, chemical,   *
  8. * manual or otherwise, without the prior written permission of  *
  9. * Commodore Amiga Incorporated, 983 University Ave, #D          *
  10. * Los Gatos, CA 95030                                           *
  11. *                                                               *
  12. ****************************************************************/
  13.  
  14. /*** library.asm ***/
  15.  
  16. *** Info Library Interface Functions ***
  17.  
  18. *------ Included Files -----------------------------------------------
  19.  
  20.         INCLUDE         'exec/types.i'
  21.         INCLUDE         'exec/nodes.i'
  22.         INCLUDE         'exec/lists.i'
  23.         INCLUDE         'exec/memory.i'
  24.         INCLUDE         'exec/ports.i'
  25.         INCLUDE         'exec/libraries.i'
  26.         INCLUDE         'exec/devices.i'
  27.         INCLUDE         'exec/tasks.i'
  28.         INCLUDE         'exec/io.i'
  29.         INCLUDE         'exec/strings.i'
  30.         INCLUDE         'exec/initializers.i'
  31.         INCLUDE         'exec/resident.i'
  32.  
  33.  
  34. *------ Imported Globals ---------------------------------------------
  35.  
  36.  
  37.  
  38. *------ Imported Functions -------------------------------------------
  39.  
  40.         XREF    _main
  41.         XREF    _InfoOpen
  42.         XREF    _InfoClose
  43.         XREF    _InfoExpunge
  44.  
  45.  
  46. *------ Exported Globals ---------------------------------------------
  47.  
  48.         XDEF    _SysBase
  49.         XDEF    _InfoBase
  50.         XDEF    _InfoSegList
  51.         XDEF    _InfoName
  52.  
  53.  
  54. *------ Exported Functions -------------------------------------------
  55.  
  56. InfoTag:
  57.                 DC.W    RTC_MATCHWORD
  58.                 DC.L    InfoTag
  59.                 DC.L    EndMarker
  60.                 DC.B    RTF_AUTOINIT
  61.                 DC.B    1               version
  62.                 DC.B    NT_LIBRARY
  63.                 DC.B    0               priority
  64.                 DC.L    _InfoName
  65.                 DC.L    _InfoIdStr
  66.                 DC.L    InfoInit
  67.  
  68. _InfoIdStr      DC.B    'info V1.0',13,10,0
  69.                 DS.W    0
  70.  
  71. InfoInit:
  72.                 DC.L    LIB_SIZE
  73.                 DC.L    libFuncInit
  74.                 DC.L    libStructInit
  75.                 DC.L    init
  76.  
  77. init:
  78.         ;------ This is called from within MakeLibrary, after
  79.         ;       all the memory has been allocated
  80.                 move.l  a6,_SysBase
  81.                 move.l  d0,_InfoBase
  82.                 move.l  a0,_InfoSegList
  83.                 rts
  84.  
  85.  
  86. libStructInit:
  87.                 INITBYTE    LN_TYPE,NT_LIBRARY
  88.                 INITLONG    LN_NAME,_InfoName
  89.                 INITWORD    LIB_VERSION,1
  90.                 INITLONG    LIB_IDSTRING,_InfoIdStr
  91. *               INITBYTE    LIB_FLAGS,LIBF_SUMUSED!LIBF_CHANGED
  92.                 DC.W        0
  93.  
  94.  
  95. libFuncInit:
  96.                 DC.L    open
  97.                 DC.L    close
  98.                 DC.L    expunge
  99.                 DC.L    extfunc
  100.                 DC.L    _main
  101.                 DC.L    -1
  102.  
  103. open:
  104.                 move.l  a6,-(sp)
  105.                 jsr     _InfoOpen
  106.                 addq.l  #4,sp
  107.                 rts
  108.  
  109. close:
  110.                 move.l  a6,-(sp)
  111.                 jsr     _InfoClose
  112.                 addq.l  #4,sp
  113.                 rts
  114.  
  115. expunge:
  116.                 move.l  a6,-(sp)
  117.                 jsr     _InfoExpunge
  118.                 addq.l  #4,sp
  119. extfunc:
  120.                 rts
  121.  
  122.  
  123. _SysBase        DC.L    0
  124. _InfoBase       DC.L    0
  125. _InfoSegList    DC.L    0
  126. _InfoName       DC.B    'info.library',0
  127.                 DS.W    0
  128.  
  129. EndMarker
  130.  
  131.  
  132.         END
  133.  
  134.  
  135.  
  136. /*** libcode.c   ***/
  137.  
  138. #include "exec/types.h"
  139. #include "exec/libraries.h"
  140.  
  141. extern APTR InfoSegList;
  142.  
  143. struct Library *
  144. InfoOpen(lib)
  145.     struct Library *lib;
  146. {
  147.     kprintf ("opening...\n");
  148.  
  149.     lib -> lib_Flags &= ~LIBF_DELEXP;
  150.     (lib -> lib_OpenCnt)++;
  151.  
  152.     return lib;
  153. }
  154.  
  155.  
  156. APTR
  157. InfoExpunge(lib)
  158.     struct Library *lib;
  159. {
  160.     APTR seglist;
  161.  
  162.     kprintf ("expunging...\n");
  163.  
  164.     Forbid ();
  165.  
  166.     if (lib -> lib_OpenCnt > 0) {
  167.         lib -> lib_Flags |= LIBF_DELEXP;
  168.         Permit ();
  169.         return 0;
  170.     }
  171.  
  172.     seglist = InfoSegList;
  173.     kprintf ("seglist= %lx", seglist);
  174.  
  175.     Remove (lib);
  176.  
  177.     FreeMem ((long) lib - (long) (lib -> lib_NegSize),
  178.             (lib -> lib_NegSize + lib -> lib_PosSize));
  179.     Permit ();
  180.  
  181.     return seglist;
  182. }
  183.  
  184. APTR
  185. InfoClose(lib)
  186.     struct Library *lib;
  187. {
  188.     kprintf ("closing...\n");
  189.  
  190.     if (--(lib -> lib_OpenCnt) == 0) {
  191.         if ((lib -> lib_Flags & LIBF_DELEXP) != 0) {
  192.             return (InfoExpunge (lib));
  193.         }
  194.     }
  195.  
  196.     return 0;
  197. }
  198.  
  199.  
  200.  
  201. main()
  202. {
  203.     kprintf ("main info program\n");
  204. }
  205.